package com.self.cgqcompose.ui.composables

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.dp

@Composable
fun CustomBoxWithOverflow(
    modifier: Modifier = Modifier,
    content: @Composable () -> Unit
) {
    Layout(
        modifier = modifier,
        content = content,
        measurePolicy = { measurables, constraints ->
            val placeables = measurables.map { measurable ->
                // Measure with original constraints to get intrinsic width
                val intrinsicWidth = measurable.minIntrinsicWidth(height = 0)
                // Enforce the child's requested width
                measurable.measure(
                    constraints.copy(

                        maxWidth = Int.MAX_VALUE,
                        minHeight = 0,
                        maxHeight = Int.MAX_VALUE
                    )
                )
            }
            val width = constraints.maxWidth
            val height = 50.dp.roundToPx().coerceIn(constraints.minHeight, constraints.maxHeight)
            layout(width, height) {
                placeables.forEach { placeable ->
                    placeable.placeRelative(
                        x = (width - placeable.width) / 2, // 水平居中
                        y = height - placeable.height // 底部对齐
                    )
                }
            }
        }
    )
}